package com.hjh.netty.elect.demo5.enums;

import com.hjh.netty.elect.demo5.parser.impl.*;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum UpLoadDataParserEnum {
    Main1Sub1Ver0("Main1Sub1Ver0", UpLoadDataMain1Sub1Ver0.class),
    Main1Sub1Ver1("Main1Sub1Ver1", UpLoadDataMain1Sub1Ver1.class),
    Main1Sub1Ver2("Main1Sub1Ver2", UpLoadDataMain1Sub1Ver2.class),
    Main1Sub2Ver0("Main1Sub2Ver0", UpLoadDataMain1Sub2Ver0.class),
    Main1Sub2Ver1("Main1Sub2Ver1", UpLoadDataMain1Sub2Ver1.class),
    Main1Sub3Ver0("Main1Sub3Ver0", UpLoadDataMain1Sub3Ver0.class),
    Main1Sub3Ver1("Main1Sub3Ver1", UpLoadDataMain1Sub3Ver1.class),
    Main1Sub3Ver4("Main1Sub3Ver4", UpLoadDataMain1Sub3Ver4.class),
    Main1Sub4Ver0("Main1Sub4Ver0", UpLoadDataMain1Sub4Ver0.class),
    Main2Sub1Ver0("Main2Sub1Ver0", UpLoadDataMain2Sub1Ver0.class),
    Main3Sub1Ver0("Main3Sub1Ver0", UpLoadDataMain3Sub1Ver0.class),
    ;
    private String parserType;
    private Class parserHandleClz;

    /**
     * 获取处理类型
     *
     * @param upDataMainType
     * @param upDataSubType
     * @param upDataTypeVer
     * @return
     */
    public static String obtainParserType(int upDataMainType, int upDataSubType, int upDataTypeVer) {
        return "Main" + upDataMainType + "Sub" + upDataSubType + "Ver" + upDataTypeVer;
    }

    /**
     * 获取处理类型
     *
     * @param upDataMainType
     * @param upDataSubType
     * @param upDataTypeVer
     * @return
     */
    public static UpLoadDataParserEnum obtainInstance(int upDataMainType, int upDataSubType, int upDataTypeVer) {
        String parserType = obtainParserType(upDataMainType, upDataSubType, upDataTypeVer);

        for (UpLoadDataParserEnum value : UpLoadDataParserEnum.values()) {
            if (value.getParserType().equals(parserType)) {
                return value;
            }
        }
        return null;
    }
}
